<?php

namespace App\Http\Controllers\Admin;
use App\Article;
use App\Http\Requests\ArticleRequest;
use Illuminate\Support\Facades\Cache;

class ArticleController extends AdminController
{
    public function index()
    {
        $list = Article::pagInate(5);
        return view('admin.article.index',compact('list'));
    }

    public function create()
    {
        $parent = Cache::get('Categroys');
        return view('admin.article.add',compact('parent'));
    }

    public function store(ArticleRequest $request)
    {
        Article::create($request->except('_token','_method'));
        return redirect('admin/article');
    }

    public function edit($id)
    {
        $parent = Cache::get('Categroys');
        $article = Article::find($id);
        return view('admin.article.edit',compact('article','parent'));
    }

    public function update(ArticleRequest $request,$id)
    {
        Article::where('id',$id)->update($request->except('_token','_method'));
        return redirect('admin/article');
    }

    public function destroy($id)
    {
        Article::where('id',$id)->delete();
        return redirect('admin/article');
    }

    /*markdown修改*/
    public function markdown($id)
    {
        $content = Article::where('id',$id)->value('content');
        return view('admin.ifram.markdownEdit',compact('content'));
    }

}
